<template lang="pug">
mt-dialog(
  v-model="appmodel"
  cancel-text="取消"
  title="标本采集"
  confirm-text="采集"
  :on-close="updateModel"
  :on-cancel="updateModel"
  :on-confirm="updateConfirmModel"
  :confirm-loading="loadingMap.batchGenerateBarcode"
  width="800"
)
  h3 确认后不可撤回 请谨慎操作！
    mt-table(
      v-bind="tableProps"
      style="margin-top: var(--mt-margin);"
    )
</template>

<script setup lang="ts">
import { useApi } from "@scmt/core-api";
import { type TableProps, useNotify } from "@scmt/common-components";
import { type SpecimenEntity } from "@scmt/api-lis-specimen";
import { useRequest } from "@scmt/common-hooks";
import { ESpecimenStatus } from "@scmt/api-common";
//添加 Props属性
const props = defineProps({
  selectionRow: {
    type: Array as PropType<SpecimenEntity[]>,
    default: () => [],
  },
});
const $api = useApi();
const $notify = useNotify();

const appmodel = defineModel({
  default: false,
});
const emit = defineEmits(["save"]);
const updateModel = () => {
  appmodel.value = false;
};

const { request, loadingMap } = useRequest({
  batchGenerateBarcode: (params: any) => {
    return $api.lis.specimen.batchGenerateBarcode(params).then(() => {
      $notify.success("采集成功");
      emit("save");
    });
  },
});

const updateConfirmModel = () => {
  const specimenIdData = ([] as SpecimenEntity[])
    .concat(props.selectionRow)
    .map((item) => {
      return item.id;
    })
    .filter((item) => item != undefined);
  request("batchGenerateBarcode", {
    specimenList: specimenIdData,
    status: ESpecimenStatus.Collection,
  });
};
const tableProps = computed(() => {
  const tableProps: TableProps = {
    data: props.selectionRow.filter((item) => item.id != undefined),
    columns: [
      {
        prop: "patientName",
        label: "姓名",
        width: 90,
      },
      {
        prop: "sex",
        label: "性别",
        width: 80,
      },
      {
        prop: "age",
        label: "年龄",
        width: 80,
      },
      {
        prop: "applicationProject",
        label: "申请项目",
        tooltip: true,
      },
      {
        prop: "sampleContainer",
        label: "标本容器",
        tooltip: true,
      },
      {
        prop: "specs",
        label: "采集规格",
        tooltip: true,
      },
      {
        prop: "bloodCollectionVolume",
        label: "标本量",
        tooltip: true,
      },
    ],
  };
  return tableProps;
});
</script>
